﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZDH004;
using Com.LongER.Framework.Utils.LogUtils;
public partial class ZDH004 : ABasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZDH004";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "车辆跟踪查询画面";
            //清空画面中的输入框
            #region
            proc清空_Init("0");

            #endregion
            //焦点位于用户ID输入框中
            this.txt车牌号.Focus();
        }

    }

    protected void btn执行_Click(object sender, EventArgs e)
    {
        //结果栏清空
        #region
        //总件数清空
        this.txt总件数.Text = string.Empty;
        //标题行以外全部移除
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        lblMsgCD.Text = "  ";

        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsg.Text = "  ";
        #endregion

        //起始日期与终了日期的格式进行转换
        string strNewStaDay ="";
        string strNewEndDay = "";
        string strNewStaHour = "";
        string strNewEndHour = "";
        strNewStaDay = this.txt起始日时_Day.Text.Replace("/", "");
        strNewEndDay = this.txt终了日时_Day.Text.Replace("/", "");

        if (!String.IsNullOrWhiteSpace(this.txt起始日时_Hour.Text))
        {
            strNewStaHour = this.txt起始日时_Hour.Text;
        }

        if (!String.IsNullOrWhiteSpace(this.txt终了日时_Hour.Text))
        {
            strNewEndHour = this.txt终了日时_Hour.Text;
        }


        //起始日期与终了日期进行比较
        if (string.Compare(strNewStaDay, strNewEndDay)>0)
        {
            this.SetMessage("ZDH004", "IZDH004000", MSG_LEVEL.Error);
            this.txt起始日时_Day.Focus();
            return; 
        }

        //起始日期与终了日期相同时,时间进行比较
        if (string.Compare(strNewStaDay, strNewEndDay) == 0 && string.Compare(strNewStaHour, strNewEndHour) > 0)
        {
            this.SetMessage("ZDH004", "IZDH004001", MSG_LEVEL.Error);
            this.txt终了日时_Hour.Focus();
            return;
        }



        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("CHEPAI_NUM", this.txt车牌号.Text.ToString());
        dic.Add("STA_DAY", strNewStaDay.ToString());
        dic.Add("STS_HOUR", strNewStaHour.ToString());
        dic.Add("END_DAY", strNewEndDay.ToString());
        dic.Add("END_HOUR", strNewEndHour.ToString());

        //
        if (this.hidPageNo.Value == string.Empty) this.hidPageNo.Value = "1";
        dic.Add("PAGE_NO", this.hidPageNo.Value);

        CZDH004 instance = new CZDH004();

        ZDH004DS.T_CHESTADataTable dt = instance.GetCheStaList(dic);

        #region
        //查询结果不为空时
        if (dt.Count > 0)
        {
            this.txt总件数.Text = dt.Count.ToString();
        }
        //查询结果为空时
        else
        {
            String msg = MessageUtil.GetMessage("GTH002", "IGTH002001");

            lblMsgCD.Text = "IGTH002001";
            lblMsg.Text = msg;

            return;
        }

        int rowid = 0;
        //
        foreach (var dr in dt)
        {
            //创建新行
            TableRow row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

            //选择
            TableCell cell = GetTableCell(width: 30, rowspan: 1);
            //
            RadioButton rb = new RadioButton();
            rb.ID = "rb" + rowid;
            rb.GroupName = "rad";
            if (rowid == 0) rb.Checked = true;

            cell.Controls.Add(rb);
            row.Cells.Add(cell);//插入单元格

            //车牌号
            cell = GetTableCell(width: 70);
            cell.Text = dr.CHEPAI_NUM;
            row.Cells.Add(cell);

            //车辆行驶日时
            cell = GetTableCell(width: 120);
            cell.Text = dr.JL_DATE.Substring(0, 4) + '年' + dr.JL_DATE.Substring(4, 2) + '月' + dr.JL_DATE.Substring(6, 2) + '日' + dr.JL_TIME + '时';
            row.Cells.Add(cell);

            //所在省市
            cell = GetTableCell(width: 60);
            cell.Text = dr.SUOZAI_SHENGSHI + dr.SENS_HANZI;
            row.Cells.Add(cell);

            //路段名
            cell = GetTableCell(width: 60);
            cell.Text = dr.SUOZAI_LUDUAN;
            row.Cells.Add(cell);

            //详细路段
            cell = GetTableCell(width: 200);
            cell.Text = dr.DETAIL_LUDUAN;
            row.Cells.Add(cell);

            //运营状态
            cell = GetTableCell(width: 60);
            cell.Text = dr.YUNYING_STA + dr.YYZT_HANZI;
            row.Cells.Add(cell);

            //运输状态
            cell = GetTableCell(width: 60);
            cell.Text = dr.YUNSHU_STA + dr.YSZT_HANZI;
            row.Cells.Add(cell);

            //装载状态
            cell = GetTableCell(width: 80);
            cell.Text = dr.ZHUANGZAI_STA + dr.ZZZT_HANZI;
            row.Cells.Add(cell);

            //装载率
            cell = GetTableCell(width: 90);
            cell.Text = dr.ZHUANGZAI_LV + '%';
            row.Cells.Add(cell);

            this.tblList.Rows.Add(row);
            rowid++;
        }
        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        //控件的Enabled进行控制
        #region
        this.txt车牌号.Enabled = true;
        this.txt起始日时_Day.Enabled = true;
        this.txt起始日时_Hour.Enabled = true;
        this.txt终了日时_Day.Enabled = true;
        this.txt终了日时_Hour.Enabled = true;

        this.txt车牌号.Text = string.Empty;
        this.txt起始日时_Day.Text = string.Empty;
        this.txt起始日时_Hour.Text = string.Empty;
        this.txt终了日时_Day.Text = string.Empty;
        this.txt终了日时_Hour.Text = string.Empty;

        #endregion

        //总件数
        this.txt总件数.Text = string.Empty;

        //数据表清空
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //清除时，各个控件的属性进行初期化
        proc清空_Init("0");
        #endregion
    }

    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }
}